home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 3.7 KB | 177 lines | [TEXT/MPS ] |
- /*
- File: CRecipientIterator.cp
-
- Contains: xxx put contents here xxx
-
- Written by: Tim Harnett
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/11/95 TMH added IsLast()
- <1> 9/20/94 TMH Abandon RoadsideRest embrace Mercury
- 6/15/94 TMH xxx put comment here xxx
-
- To Do:
- */
-
- #ifndef __STRING__
- #include "String.h"
- #endif
-
-
- #ifndef __CRecipientIterator__
- #include "CRecipientIterator.h"
- #endif
-
-
- //-----------------------------------------
- // C R e c i p i e n t I t e r a t o r
- //-----------------------------------------
-
-
-
- //--------------------------------------------------------------------------
- CRecipientIterator::CRecipientIterator(MailMsgRef msgRef,MailAttributeID recipientKind)
- {
- memset(fRecipientBuffer,0xBB,sizeof(kMaxRecipSize)); // test pattern. So we can see buffer in debugger
-
- short fNumRecipientsReturned = 0;
- short fGetIndex = 0;
-
- fCurrentRecipientPtr = (OrigRecipient*)fRecipientBuffer;
-
- memset(&fPB,0,sizeof(MSAMGetRecipientsPB));
- fPB.attrID = recipientKind;
-
- fPB.startIndex = 1;
- fPB.more = true;
- fPB.nextIndex = 1;
-
- fPB.mailMsgRef = msgRef;
-
- fPB.buffer.buffer = fRecipientBuffer;
- fPB.buffer.bufferSize = kMaxRecipSize;
- fPB.more = true;
-
-
- }
-
-
-
- //--------------------------------------------------------------------------
- Boolean CRecipientIterator::More()
- {
-
- // Advice. Keep this small (its called alot)
- // More Advice. Do NOT change any values here.
-
- if( fNumRecipientsReturned == 0)
- return false;
-
-
- if( fGetIndex < fNumRecipientsReturned )
- return true;
- else
- return fPB.more;
-
-
- }
-
-
-
- //--------------------------------------------------------------------------
- void CRecipientIterator::Advance()
- {
- fGetIndex++;
-
- if( fGetIndex < fNumRecipientsReturned ) {
-
- unsigned long nextOffset = sizeof(MailOriginalRecipient) + sizeof(short) + fCurrentRecipientPtr->packedRecip.dataLength;
- nextOffset += nextOffset&1;
- fCurrentRecipientPtr = (OrigRecipient*) ((char*)fCurrentRecipientPtr + nextOffset);
-
- } else {
- if( fPB.more )
- this->GetMore();
- }
-
- return;
- }
-
-
- //--------------------------------------------------------------------------
- OrigRecipient* CRecipientIterator::FirstRecipient()
- {
- fCurrentRecipientPtr = 0;
- fNumRecipientsReturned = 0;
-
- fPB.startIndex = 1;
- fPB.nextIndex = 1;
-
- this->GetMore();
-
- return fCurrentRecipientPtr;
- }
-
-
- //--------------------------------------------------------------------------
- OrigRecipient* CRecipientIterator::NextRecipient()
- {
- if( this->More() )
- this->Advance();
- else
- fCurrentRecipientPtr = 0;
-
- return fCurrentRecipientPtr;
- }
-
-
- //--------------------------------------------------------------------------
- void CRecipientIterator::GetMore()
- {
- fNumRecipientsReturned = 0;
- fGetIndex = 0;
-
- fPB.startIndex = fPB.nextIndex;
- OSErr osErr = MSAMGetRecipients((MSAMParam *)&fPB,false);
-
- if( osErr == 0 ) {
- fNumRecipientsReturned = *(short*)fRecipientBuffer;
- if( fNumRecipientsReturned != 0 )
- fCurrentRecipientPtr = (OrigRecipient*) ((char*)fRecipientBuffer + sizeof(short));
- }
-
- }
-
-
-
-
- //-------------------------------------------------------------
- // C R e s o l v e d R e c i p i e n t I t e r a t o r
- //------------------------------------------------------------
-
-
- //--------------------------------------------------------------------------
- void CResolvedRecipientIterator::Advance()
- {
- fGetIndex++;
-
- if( fGetIndex < fNumRecipientsReturned ) {
-
- unsigned long nextOffset = sizeof(MailResolvedRecipient) + sizeof(short) + ((ResolvedRecipient*)fCurrentRecipientPtr)->packedRecip.dataLength;
- nextOffset += nextOffset&1;
- fCurrentRecipientPtr = (OrigRecipient*) ((char*)fCurrentRecipientPtr + nextOffset);
-
- } else {
- if( fPB.more )
- this->GetMore();
- }
-
- return;
- }
-
-
-
-